﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Generic;
using FineUI;

public partial class Manager_SysComInfo : System.Web.UI.PageEx
{
    private string strPageCode = "S0000D";
    private string strLoginResult = string.Empty;

    private int iPageCount = 0;
    private int iRecordCount = 0;
    private string strQuery = string.Empty;
    private string strSelectLang = "CN";

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!DalEx.DbManagerEx.CheckLoginRight(UserType, UserId, strPageCode, ref strLoginResult))
        {
            FineUI.Alert.Show(strLoginResult, FineUI.MessageBoxIcon.Warning);
            Response.Redirect("Login.aspx");
        }
        if (!Page.IsPostBack)
        {
            ViewState["SelectLang"] = strSelectLang;
            DataBinds();
        }
    }
    private void DataBinds()
    {
        strSelectLang = Convert.ToString(ViewState["SelectLang"]);
        string strDbName = strSelectLang.CompareTo("EN") == 0 ? "dbEnCompInfo" : "dbCompInfo";
        DataSet ds = WebBase.Comm.SelectByPage(strDbName, "*", strQuery, "cId", "cId", 0, 1, gridList.PageSize, gridList.PageIndex + 1, out iPageCount, out iRecordCount);
        gridList.RecordCount = iRecordCount;
        gridList.DataSource = ds;
        gridList.DataBind();
        btnCNVer.Enabled = strSelectLang.CompareTo("EN") == 0;
        btnENVer.Enabled = strSelectLang.CompareTo("CN") == 0;
    }
    protected void btnCNVer_Click(object sender, EventArgs e)
    {
        ViewState["SelectLang"] = "CN";
        DataBinds();
    }
    protected void btnENVer_Click(object sender, EventArgs e)
    {
        ViewState["SelectLang"] = "EN";
        DataBinds();
    }
    protected void btnAddCompInfo_Click(object sender, EventArgs e)
    {
        #region back
        //strSelectLang = Convert.ToString(ViewState["SelectLang"]);
        //List<int> lstSelectRowId = WebBase.Comm.GetGridSeleteRowId(gridList);
        //if (lstSelectRowId.Count == 1)
        //{
        //    int iSelectCompInfoId = lstSelectRowId[0];
        //    if (strSelectLang.CompareTo("EN") == 0)
        //    {
        //        Model.DbEnCompInfo compInfo = DalEx.DbEnCompInfoEx.Select(iSelectCompInfoId);

        //        if (compInfo != null)
        //        {
        //            hfCompId.Text = compInfo.CId.ToString();
        //            txtName.Text = compInfo.CName;
        //            txtName.Readonly = true;
        //            txtCode.Text = compInfo.CCode;
        //            txtCode.Readonly = true;
        //            txtKeywords.Text = compInfo.CKeywords;
        //            txtDescription.Text = compInfo.CDescription;
        //            cboxStatus.Checked = Convert.ToBoolean(compInfo.CStatus);
        //            UEditor1.Value = HttpUtility.HtmlDecode(compInfo.CNotes);
        //        }
        //        winCompInfo.Popup = true;
        //    }
        //    else
        //    {
        //        Model.DbCompInfo compInfo = DalEx.DbCompInfoEx.Select(iSelectCompInfoId);

        //        if (compInfo != null)
        //        {
        //            hfCompId.Text = compInfo.CId.ToString();
        //            txtName.Text = compInfo.CName;
        //            txtName.Readonly = true;
        //            txtCode.Text = compInfo.CCode;
        //            txtCode.Readonly = true;
        //            txtKeywords.Text = compInfo.CKeywords;
        //            txtDescription.Text = compInfo.CDescription;
        //            cboxStatus.Checked = Convert.ToBoolean(compInfo.CStatus);
        //            UEditor1.Value = HttpUtility.HtmlDecode(compInfo.CNotes);
        //        }
        //        winCompInfo.Popup = true;
        //    }
        //}
        //else if (lstSelectRowId.Count > 1)
        //{
        //    Alert.Show("抱歉，请不要选择多项进行编辑！", MessageBoxIcon.Warning);
        //}
        //else
        //{
        //    sfCompInfo.Reset();
        //    //hfCompId.Text = string.Empty;
        //    //txtName.Text = string.Empty;
        //    //txtName.Readonly = false;
        //    //txtCode.Text = string.Empty;
        //    //txtCode.Readonly = false;
        //    //txtKeywords.Text = string.Empty;
        //    //txtDescription.Text = string.Empty;
        //    //cboxStatus.Checked = false;
        //    //htmlNotes.Text = string.Empty;
        //    winCompInfo.Popup = true;
        //}
        #endregion

        winForm.IFrameUrl = "CompInfoAdd.aspx";
        winForm.IFrameName = "新增企业信息";
        winForm.Title = "新增企业信息";
        winForm.Hidden = false;
    }
    protected void btnDeleteCompInfo_Click(object sender, EventArgs e)
    {
        List<int> lstSelectRowId = WebBase.Comm.GetGridSeleteRowId(gridList);
        if (lstSelectRowId.Count > 0)
        {
            ArrayList lstSql = null;
            lstSql = new ArrayList();
            if (strSelectLang.CompareTo("EN") == 0)
            {
                foreach (int iTemp in lstSelectRowId)
                {
                    lstSql.Add("delete from dbEnCompInfo where cId=" + iTemp);
                }
            }
            else
            {
                foreach (int iTemp in lstSelectRowId)
                {
                    lstSql.Add("delete from dbCompInfo where cId=" + iTemp);
                }
            }
            if (SqlHelper.ExecSql(lstSql) > 0)
            {
                DataBinds();
                Alert.Show("企业资料删除成功！", MessageBoxIcon.Information);
            }
        }
        else
        {
            Alert.Show("请选择要删除项！", MessageBoxIcon.Warning);
        }
    }
    protected void ddlPageSize_SelectedIndexChanged(object sender, EventArgs e)
    {
        int iPageSize = 20;
        int.TryParse(ddlPageSize.SelectedValue, out iPageSize);
        gridList.PageSize = iPageSize;
        DataBinds();
    }
    protected void btnRefresh_Click(object sender, EventArgs e)
    {
        DataBinds();
    }
    protected void winForm_Close(object sender, FineUI.WindowCloseEventArgs e)
    {
        DataBinds();
    }
}
